"""
@name : 3-1.线程锁-互斥锁
@author : wenyao
@projectname: sanchuanglianxi
"""
#互斥锁  Lock/RLock

# import threading
# from threading import Thread
# import time
# num = 0
#
# def sum_num(i):
#    lock.acquire()  # 加锁
#    global num
#    time.sleep(1)
#    num += i
#    print(num)
#    lock.release()  #释放锁
#
# def func1():
#     pass
#
# list = []
# lock = threading.Lock()
# for i in range(6):
#     t = Thread(target = sum_num, args=(i,))
#     list.append(t)
#     t.start()

##############
#Lock嵌套就产生了死锁
#acquire与release必须成对存在
#RLock可以嵌套，Lock不可嵌套

import threading
lock = threading.RLock()

print("start......")
lock.acquire()
print("get acquire 1")
lock.acquire()
print("get acquire 2")
lock.release()
print("release acquire 1")
lock.release()
print("release acquire 2")